/*
 * Copyright 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.beepmystuff;

import com.google.beepmystuff.BmsClient.SessionStorage;

/**
 * An {@link Injector} that must be provided with explicit dependencies, for
 * tests.
 */
public class TestInjector extends Injector {
  private BmsHttpClient bmsHttpClient;
  private BmsLowLevelClient bmsLowLevelClient;
  private Preferences preferences;
  private SessionStorage sessionStorage;

  @Override
  public synchronized BmsHttpClient getBmsHttpClient() {
    if (bmsHttpClient == null) {
      throw new IllegalStateException("no injected BmsHttpClient available");
    }
    return bmsHttpClient;
  }

  public TestInjector setBmsHttpClient(BmsHttpClient bmsHttpClient) {
    this.bmsHttpClient = bmsHttpClient;
    return this;
  }

  @Override
  public synchronized BmsLowLevelClient getBmsLowLevelClient() {
    if (bmsLowLevelClient == null) {
      throw new IllegalStateException("no injected BmsLowLevelClient available");
    }
    return bmsLowLevelClient;
  }

  public TestInjector setBmsLowLevelClient(BmsLowLevelClient bmsLowLevelClient) {
    this.bmsLowLevelClient = bmsLowLevelClient;
    return this;
  }

  @Override
  public synchronized Preferences getPreferences() {
    if (preferences == null) {
      throw new IllegalStateException("no injected Preferences available");
    }
    return preferences;
  }

  public TestInjector setPreferences(Preferences preferences) {
    this.preferences = preferences;
    return this;
  }

  @Override
  public synchronized SessionStorage getSessionStorage() {
    if (sessionStorage == null) {
      throw new IllegalStateException("no injected SessionStorage available");
    }
    return sessionStorage;
  }

  public TestInjector setSessionStorage(SessionStorage sessionStorage) {
    this.sessionStorage = sessionStorage;
    return this;
  }
}
